import javax.swing.tree.TreeNode;
import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;

//public class TreeNode {
//    int val = 0;
//    TreeNode left = null;
//    TreeNode right = null;
//    public TreeNode(int val) {
//     this.val = val;
//   }
//  }

public class Main2 {


    //二叉树中最大路径和
//    public static int ret = -1010;
//    public int maxPathSum (TreeNode root) {
//        dfs(root);
//        return ret;
//    }
//    public static int dfs(TreeNode root){
//        if (root == null) return 0;
//
//        int l = Math.max(0,dfs(root.left));
//        int r = Math.max(0,dfs(root.right));
//        ret = Math.max(ret,root.val+l+r);
//        return root.val+Math.max(l,r);
//    }


    //体操队形
    public static  int N = 15;
    public static int n,ret;
    public static boolean[] vis = new boolean[N];
    public static int[] arr = new int[N];

    public static void dfs(int pos){
        if(pos == n+1){
            ret++;
            return;
        }
        for (int i = 1; i <= n; i++) {
            if(vis[i] == true) continue;
            if(vis[arr[i]]) return;
            vis[i] = true;
            dfs(pos+1);
            vis[i] = false;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        for (int i = 1; i <= n; i++) {
            arr[i] = in.nextInt();
        }
        dfs(1);
        System.out.println(ret);
    }





    //游游的重组偶数
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static  Read in = new Read();
    public static void Swap(char[] s,int i,int j ){
        char tmp = s[i];
        s[i] = s[j];
        s[j] = tmp;
    }

    public static void main1(String[] args) throws IOException{
        int q = in.nextInt();
        while(q-- != 0){
            char[] s = in.next().toCharArray();
            int n = s.length;

            for (int i = n-1; i >= 0; i--) {
                if((s[i]-'0') % 2 == 0){
                    Swap(s,i,n-1);
                    break;
                }
            }
            if((s[n-1] - '0')%2 == 0){
                out.println(s);
            }else{
                out.println(-1);
            }
        }
        out.close();
    }


}

class Read{
    StringTokenizer st  =new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String next() throws IOException {
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    String nextLine() throws IOException{
        return bf.readLine();
    }
    int nextInt() throws IOException{
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException{
        return Long.parseLong(next());
    }
    double nextDouble() throws IOException{
        return Double.parseDouble(next());
    }
}
